<?php

class EventManager_EventController extends Zend_Controller_Action
{
	protected $_model;

	public function init()
	{
		/* Initialize action controller here */
		$this->_model = new EventManager_Model_Event();
		$this->view->newForm = $this->getNewForm();
		
	}

	public function indexAction()
	{
		// action body

	}

	public function listAction()
	{
		$page = $this->getRequest()->getUserParam('page');
		if (null == $page){
			$page = 1;
		}
		$this->view->events = $this->_model->getAllEvents(null,null,$page);
	}
	
	
	/**
	 * 
	 * @return unknown_type
	 */
	public function newAction(){
		
	}
	/**
	 * 
	 * @return unknown_type
	 */
	public function saveAction(){
	 	$request = $this->getRequest();
	 	$form = $this->getNewForm();
	 	
	 	//var_dump($request->getPost());exit;
	 	if(!$request->isPost()){
	 		return $this->_helper->redirector('new');
	 	}
	 	$evtId = $this->_model->add($request->getPost());
	 	if(false === $evtId){
	 		return($this->render('new'));
	 	}
	}
	 /**
	 * 
	 * @return unknown_type
	 */	
	private function getNewForm(){
		$urlHelper= $this->_helper->getHelper('url');
		$this->_forms['new'] = $this->_model->getForm('eventNew');
		$this->_forms['new']->setAction($urlHelper->url(array(
    		'controller' => 'event',
    		'action'	=>'save'
    		),
    		'default'
    		));
    		$this->_forms['new'];
    	 return $this->_forms['new'];
	}
	
	

}



